# '''
# 库： Python预先编写的代码
# '''
# import random
#
# coin = random.choice(["正", "反"])
# print(coin)
#
# x = random.randint(88, 99)
# print(x)
#
# import statistics
# y = statistics.mean([2, 2, 2, 2, 2])
# print(y)
#
# '''
# 包（packages）: 非Python预先编写的代码、网络上、分发
# PyPI (Python包索引)： 安装、卸载、加载 ： pip
# pip install cowsay
# '''
# # import cowsay
# # say = input("输入你想说的话： ")
# # cowsay.pig(say)
#
# # API  应用程序编程接口 requests
# # import requests
# # # response = requests.get("https://open.iciba.com/dsapi/") # 模拟浏览器对该网址发起请求
# # response = requests.get("https://v1.jinrishici.com/all.json") # 模拟浏览器对该网址发起请求
# # print(response.json()) # json
#
# import emoji
# msg = input("请输入你想说的话： ")
# convert = emoji.emojize(msg)
# print(convert)
#
# '''
# 文件
# '''
# list1 = []
#
# for i in range(3):
#     name = input("what's your name? ")  # php --> name
#     list1.append(name)
#
# for j in list1:
#     print(f"hello {j}")

# for i in range(3):
#     name = input("what's your name? ")
#     file = open("names.txt", "a", encoding="utf-8")  # r(read) w(write) a(append)
#     file.write(name + '\n')
#     file.close()

# r(read) w(write) a(append)
# file = open("names.txt", "r", encoding="utf-8")
# line = file.readline()
# print(line)
# file.close()

# file = open("names.txt", "r", encoding="utf-8")
# lines = file.readlines() # 读取所有的行
# file.close()
# print(lines)

# with open("names.txt", "r", encoding="utf-8") as file:
#     lines = file.readlines()
# print(lines)

# with open(r"C:\Users\student001\Desktop\myscore.csv","r", encoding="utf8") as file:
#     lines = file.readlines()
#     print(lines)

# 二进制文件
# from PIL import Image
# images = []
# img1 = Image.open("costume1.gif")
# images.append(img1)
# img2 = Image.open("costume2.gif")
# images.append(img2)
#
# images[0].save(
#     "mycat.gif",
#     save_all=True,
#     append_images=[images[1]],
#     duration=100,
#     loop=0
# )

# from PIL import Image
# images = []
# for i in range(1, 8):
#     img = Image.open(f"ll{i}.PNG")
#     images.append(img)
#
# images[0].save(
#     "ll.gif",
#     save_all=True,
#     append_images=[i for i in images[1:]],
#     duration=100,
#     loop=0
# )


# r w a
# file_name = input("你要读取哪个文件的代码： ")
# # 判断输入的文件是否合法
# if not file_name.endswith(".py"):
#     exit()  # 退出程序
#
# with open(file_name, "r", encoding="utf8") as file:
#     lines = file.readlines()
#
# count = 0
# for i in lines:
#     if i == "\n":  # 排除空行
#         continue
#     elif i.lstrip().startswith("#"):  # 排除注释行
#         continue
#     count += 1
#
# print(f"代码行数{count}")
# pip install Pillow

# from PIL import Image, ImageOps
# phot = input("输入（即打开）要读取的JPEG或PNG的名称（或路径）")
# save_name = input("输入（即打开）要保存的JPEG或PNG的名称（或路径）")
# phot = Image.open(phot)
# shirt = Image.open("shirt.png")
# phot = ImageOps.fit(phot, (600, 600))
# phot.paste(shirt, shirt)
# phot.save(save_name)

'''
元组
'''
list1 = []
# 增
list1.append(-1)
list1.append(-2)
list1.append(-5)
print(list1)
# 删
list1.remove(-2)  # 根据元素删除
list1.pop(0)  # 根据下标删除
print(list1)
# 改
list1[0] = 5
print(list1)
# 查
list1.append(9)
list1.append(90)
list1.append(999)
list1.append(900)
list1.append(9999)
print(list1[-2])  # 查询 900
print(list1[2])  # 90
print(list1[-2])  # 9

tuple1 = ('A', 'P', 'P', 'L', 'E')  # 声明一个元组
tuple2 = ('E', 'L', 'P', 'P', 'A')  # 声明一个元组
x = tuple1 + tuple2
print(x)
# 查
print(tuple1[3])
print(tuple1[-2])
# 增加
# tuple[3] = 'Q' # 不能后期增加元素
# 删除
# tuple.remove('P') # 不支持删除
# tuple.pop(2)
# 修改
# # tuple.append('W') # 不支持修改
# s = "123"
# x = int(s)
# print(s)
# list2 = list(tuple1)
# print(tuple(list2))
# '''
# 解包
# '''
# name1, name2 = ("周杰伦", "杰周伦")
# print(name1)
# print(name2)
#
# t2 = (1, 99, -9, 2, 19, -9, -9, -9)
# t3 = sorted(t2)
# print(tuple(t3))
#
# # len
# print(len(t2))
# # index
# print(t2.index(-9))
# # count
# print(t2.count(-9))
#
# # 集合（set） 唯一性
# # ()[]{}
# l1 = [1, 6, 7, 8, 8, 9, 9, 7]
# s1 = list(set(l1))
# print(s1)

'''
函数
'''

# def add_two(x, y): # 声明函数
#     print(x % y)
#
# add_two(1,3) # 位置参数
# add_two(y=3, x=12) # 关键字参数

# def add_two(x, y, z=5):  # 声明函数, z -> 默认值
#     print(x % y + z)


# add_two(1,3) # 位置参数
# add_two(y=3, x=12) # 关键字参数
# add_two(1, 1, -3)  # 关键字参数

'''
写一个函数，求n个数的和
'''

def add_many(x, y, *n):  # 可变参数
    print(sum(n) - x + y)


# add_many(1, 2, 3, 5, 6, 7)
# add_many(1, 2, 3)
# add_many(1, 2, 3, 1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3)


def add_two(x, y):
    return (x + y) # 返回给函数的调用者

x = add_two(1, 13)
print(x)

y = add_two(1, 19)
print(y)